<template>
	<om-page title="工作经历">
			<uni-card :titleUnderline="false" :is-full="true" style="border: none;border-radius: 1px;" titleBgColor="#eee"
			 :title="'工作经历(' + order + ')'">
				<uni-list>
					<uni-list-item>
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="开始日期" required></om-label>
							</view>
							<view class="tui-right tui-col-7">
								<picker mode="date" fields="month" :end="formdata.endDateW" @change="bindStartDateChange" :value="formdata.startDateW">
									<view>{{ formdata.startDateW || '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item >
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="结束日期" required></om-label>
							</view>
							<view class="tui-right tui-col-7">
								<picker mode="date" fields="month" :end="currentDate" :start="formdata.startDateW" @change="bindEndDateChange" :data-index='index' :value="formdata.endDateW">
									<view>{{ formdata.endDateW || '请选择' }}</view>
								</picker>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="组织名称" required></om-label>
							</view>
							<view class="tui-col-7">
								<input v-model="formdata.orgNameW" placeholder="请输入"/>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5"><om-label label="岗位名称" required></om-label></view>
							<view class=" tui-col-7">
								<input v-model="formdata.posNameW" placeholder="请输入"/>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item >
						<view class="tui-flex">
							<view class="tui-col-5"><om-label label="主要管理职能"></om-label></view>
							<view class="tui-right tui-col-7" @click="selectDuty">
								<text>{{formdata.dutyW || "请输入"}}</text>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5"><om-label label="上级主管姓名"></om-label></view>
							<view class=" tui-col-7">
								<input v-model="formdata.parentNameW" placeholder="请输入"/>
							</view>
						</view>
					</uni-list-item>
					<uni-list-item :showArrow="false">
						<view class="tui-flex">
							<view class="tui-col-5">
								<om-label label="上级主管手机"></om-label>
							</view>
							<view class="tui-col-7">
								<input v-model="formdata.parentMobileW" placeholder="请输入"/>
							</view>
						</view>
					</uni-list-item>
				</uni-list>
			</uni-card>
		<view class="padding">
			<button class="bg-green margin-bottom" @click="save" >确认</button>
			<button v-if="index != null" @click="del" class="bg-grey">删除</button>
		</view>
	</om-page>
</template>

<script>
	import dateTimePicker from '@/static/js/dateTimePicker.js';
	export default {
		data() {
			return {
				cachename:'',//公用属性，缓存名称
				index:null,//公用属性，修改时的当前明细索引
				datas:[],//公用属性，明细数据
				order:0,//公用属性，序号
				formdata:{//明细数据
					orgNameW:"",
					startDateW:'',
					endDateW:'',
					posNameW:'',
					dutyW:'',
					parentNameW:'',
					parentMobileW:'',
				},
				currentDate:dateTimePicker.getNewDate()
			}
		},
		methods: {
			selectDuty(){
				uni.navigateTo({
					url:'work-exp-func?addworktags='+ this.formdata.dutyW
				})
			},
			save(){
				let formdata = this.formdata
				if(!formdata.startDateW){
					this.om.toast("请选择开始时间")
					return
				}
				if(!formdata.endDateW){
					this.om.toast("请选择结束时间")
					return
				}
				if(!formdata.orgNameW){
					this.om.toast("请输入工作单位")
					return
				}
				if(!formdata.posNameW){
					this.om.toast("请输入职务")
					return
				}
				let _that = this
				if(this.index != null){
					Object.assign(this.datas[this.index],this.formdata)
				}else{
					this.datas.push(this.formdata)
				}
				uni.setStorage({
				  key: this.cachename,
				  data: this.datas
				})
				uni.navigateBack()
			},
			del(){
				if(this.index != null){
					this.datas.splice(this.index,1)
				}
				uni.setStorage({
				  key: this.cachename,
				  data: this.datas
				})
				uni.navigateBack()
			},
			bindStartDateChange(e){
				this.formdata.startDateW = e.detail.value
			},
			bindEndDateChange(e){
				this.formdata.endDateW = e.detail.value
			},
			initLoad(){
			}
		},
		onLoad(e){
			let index = e.index
			let _that = this
			if(e.cachename){
				this.cachename = e.cachename
				uni.getStorage({
					key: this.cachename,
					success: function(res) {
						if(res.data && res.data.length){
							_that.datas = res.data
							if(index != null && index != undefined){
								var d = res.data[index]
								Object.assign(_that.formdata,d)
								_that.order = parseInt(index)+ 1
								_that.index = parseInt(index)
							}else{
								_that.order = res.data.length + 1
							}
							
						}else{
							_that.order = 1
						}
					},
					fail() {
						_that.order = 1
					}
				});
			}else{
				uni.navigateBack({
					
				})
			}
			
			this.initLoad()
		},
		onShow() {
			let _that = this
			uni.getStorage({
				key:'select-tags',
				success:function(res) {
					_that.formdata.dutyW = res.data
					uni.removeStorage({
						key:'select-tags'
					})
				}
			})
		}
	}
</script>

<style>

</style>
